#ifndef VZLPR_ADDON_STRINGUTIL_H_
#define VZLPR_ADDON_STRINGUTIL_H_

#include <Windows.h>
#include <tchar.h>
#include <string>
#include <sstream>
#include <vector>

#ifdef _UNICODE
typedef std::wstring tstring;
typedef std::wistringstream itstringstream;
typedef wchar_t tchar;
#else
typedef std::string tstring;
typedef std::istringstream itstringstream;
typedef char tchar;
#endif

std::wstring UTF8ToUnicode(const std::string &strUTF8);

std::string UnicodeToAnsi(const std::wstring &strUnicode);

std::string UTF8ToAnsi(const std::string &strUTF8);

std::wstring AnsiToUnicode(const std::string &strAnsi);

std::string UnicodeToUTF8(const std::wstring &strUnicode);

std::string AnsiToUTF8(const std::string &strAnsi);

inline std::string ToString(char const* str)
{
  return std::string(str);
}

inline std::string ToString(std::string const& str)
{
  return str;
}

inline std::string const& ToString(std::string& str)
{
  return str;
}

inline std::string ToString(const std::wstring& str)
{
  return UnicodeToAnsi(str);
}

inline std::string ToString(wchar_t const* str)
{
  return UnicodeToAnsi(std::wstring(str));
}

inline std::wstring ToWString(wchar_t const* str)
{
  return std::wstring(str);
}

inline std::wstring ToWString(std::wstring const& str)
{
  return str;
}

inline std::wstring const& ToWString(std::wstring& str)
{
  return str;
}

inline std::wstring ToWString(const std::string& str)
{
  return AnsiToUnicode(str);
}

inline std::wstring ToWString(char const* str)
{
  return AnsiToUnicode(std::string(str));
}

#ifdef _UNICODE
#define ToTString(str) ToWString(str)
#define ToUTF8(str) UnicodeToUTF8(str)
#define FromUTF8(str) UTF8ToUnicode(str)
#else
#define ToTString(str) ToString(str)
#define ToUTF8(str) AnsiToUTF8(str)
#define FromUTF8(str) UTF8ToAnsi(str)
#endif


tstring& Trimmed(tstring &str);

tstring Format(TCHAR const* format, ...);

std::vector<tstring> Split(const tstring &str, const tstring &delim);

tstring ToLower(const tstring &str);

tstring ToUpper(const tstring &str);

template <typename T>
inline T Convert(const tstring &str) {
  itstringstream iss(str);
  T t;
  iss >> t;
  return t;
}

tstring CreateUUID();

#endif //  VZLPR_ADDON_STRINGUTIL_H_
